#e
#Title[ʏe01]
#Text[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\lib_anime_tewi.txt"
	#include_function ".\boss.txt"
	let csd		=GetCurrentScriptDirectory;
	let shotData	=csd ~ ".\shot.txt";
	let imgBoss	=csd ~ "img\dot_tewi.png";
	let imgBG1	=csd ~ "img\maho1.png";
	let imgBG2	=csd ~ "img\maho2.png";
	let xIni	=GetCenterX;
	let yIni	=GetClipMinY + 100;
	let BGn		=0;
	@Initialize {
        SetLife(1200);
	SetTimer(60);
	InitializeAction();
	LoadUserShotData(shotData);
        LoadGraphic(imgBoss);
	LoadGraphic(imgBG1);
	LoadGraphic(imgBG2);
        TMain;
	}

	@MainLoop {
	BGn++;
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	yield;
	}

	@DrawLoop {
	SetColor(255,255,255);
	SetGraphicScale(1,1);
	SetGraphicAngle(0,0,0);
	SetAlpha(225);
	DrawBoss(imgBoss);
	BG;
	}
function wait(w) {
    loop(w) { yield; }
}
    task TMain {
        yield;
standBy;
SetDamageRate(100,100);
moveA;
shotA;
}

task shotA {
loop{
wait(15);
loop(6){ 
let A=0;
let B=GetAngleToPlayer;
loop(4){
let angleB=-120;
while(angleB<121){
let angleA=-3;
while(angleA<4){
CreateShot01(GetX,GetY,2+A,angleA+B+angleB,14,0);
angleA+=6;
}
let angleA=-6;
while(angleA<7){
CreateShot01(GetX,GetY,1.6+A,angleA+B+angleB,14,0);
angleA+=6;
}
angleB+=40;
}
A+=0.8;
}
wait(20);
}
wait(20);
let C=0;
loop(50){
wait(2);
let angleA=0;
while(angleA<360){
CreateShot01(GetX+cos(angleA+C)*30,GetY+sin(angleA+C)*30,4,angleA+C,62,10);
CreateShot01(GetX+cos(angleA-C)*30,GetY+sin(angleA-C)*30,4,angleA-C,62,10);
angleA+=90;
}
C+=4;
}
}
}

   task moveA {
        let wMove =240;
	loop{	
	SetAction(ACT_MOVE,wMove);
        moveToPlayer(rand(40, 120), rand(-40, 40), wMove,
                     GetClipMinX + 48, GetClipMinY +  50,
                     GetClipMaxX - 48, GetClipMinY + 120);
        wait(wMove);
	}
	}

    sub standBy {
        let wIni = 120;

        SetMovePosition02(xIni, yIni, wIni);

        SetInvincibility(wIni);
        wait(wIni);
    }

    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;
        if(GetPlayerX < GetX) {
            x = GetX - xMove;
            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            x = GetX + xMove;
            if(right < x) {
                x = GetX - xMove;
            }
        }
        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
    }
}

}